package com.arox.springinaction.web.listener;

import java.util.Locale;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;

/**
 * Enforce UTF-8 file.encoding uppon startup.<br>
 * Please add in web.xml its definition to enable it.
 *
 * <pre>
 *  &lt;listener&gt;
 *      &lt;listener-class&gt;com.company.project.web.listener.StartupListener&lt;/listener-class&gt;
 *  &lt;/listener&gt;
 * </pre>
 *
 */
public class StartupListener implements ServletContextListener {

    private Logger logger = Logger.getLogger(StartupListener.class);

    /**
     * Called when the servlet container is starting up the application
     */
    public void contextInitialized(ServletContextEvent event) {
        if (logger.isInfoEnabled()) {
            logger.info("Servlet Context initialized...");
        }

        Locale.setDefault(Locale.ENGLISH);
    }

    /**
     * Called when the servlet container is stopping up the application
     */
    public void contextDestroyed(ServletContextEvent event) {
        if (logger.isInfoEnabled()) {
            logger.info("Servlet Context destroyed...");
        }
    }
}
